"""
日志模块
"""
import datetime
import os
import sys

import constant
from constant import temp_cfg_path
from utils.utils_operation import init_temp_cfg
from utils.utils_json import modify_cfg
from common_log import CustomFormatter, CommonLog



def get_log_path(expr_value="file_log"):
    """
    获取存储日志的路径
    :return: 路径
    """
    expr_log_dict = {
        'image_log': 'log_image_path',
        'file_log': 'log_path'
    }

    return modify_cfg(temp_cfg_path, f'$.log_config.{expr_log_dict.get(expr_value, "file_log")}')

init_temp_cfg(sys.argv[0])

custom_formatter = CustomFormatter(
    '%(asctime)s  ==> %(levelname)s  ==> %(name)s  == "%(filename)s:%(lineno)d" %(prefix)s - %(message)s',
    "%Y-%m-%d %H:%M:%S", "")

curTime = datetime.datetime.now().strftime('%H_%M_%S')

logger = CommonLog("pytest", log_path=os.path.join(constant.logs_path, f'log_{curTime}.log'), format=custom_formatter)
loggerCase = CommonLog("platform", log_path=os.path.join(constant.logs_path, f'log_case_{curTime}.log'),
                       format=custom_formatter)


if __name__ == '__main__':
    print(os.path.join(get_log_path(), f'log_case_{curTime}.log'))